package com.xuhui.demo.controller;

import com.xuhui.demo.bean.Book;
import com.xuhui.demo.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;



/**
 * @author XuHui
 * @version 1.0
 */
//这里的路径可以自己定，要返回的东西也自己定。
@RestController
@RequestMapping("/Books")
public class UserController {

    @Autowired
    private BookService bookService;

    @RequestMapping("/add")
    @PostMapping
    public void add(@RequestBody Book book){
        bookService.add(book);
        System.out.println("book = " + book);
    }

    @RequestMapping("/{id}")
    @DeleteMapping
    public void delete(@PathVariable int id){
        bookService.delete(id);
    }

    @RequestMapping("/update")
    @PutMapping
    public void update(@RequestBody Book book){
        bookService.update(book);
        System.out.println("更新成功");
    }


    @GetMapping("/{id}")
    public void find(@PathVariable int id){
        Book book = bookService.find(id);
        System.out.println("book = " + book);
    }

}
